package com.ymatou.iapi.productmanager.testcase;

import com.ymatou.iapi.productmanager.parameter.product.AddSellerProductRequest;
import com.ymatou.iapi.productmanager.parameter.product.CatalogSaveModel;
import com.ymatou.iapi.productmanager.service.UpdatePriceBySkuCall;
import com.ymatou.iapi.sellerproduct.parameter.SKUPriceBean;
import com.ymatou.iapi.sellerproduct.service.AddNewSellerProductCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.tag.P1;
import com.ymttest.business.service.ProductManagerCallServiceV2;
import com.ymttest.business.service.ProductManagerCallServiceV3;
import com.ymttest.database.model.YmtCatalogsI;
import com.ymttest.database.sqlwapper.YmtCatalogsIWapper;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.TestDataManager;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.junit.*;
import org.junit.experimental.categories.Category;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class Ts_UpdatePriceBySku {
	public static UpdatePriceBySkuCall updatePriceBySkuCall = new UpdatePriceBySkuCall();
	public static AddNewSellerProductCall addNewSellerProductCall = new AddNewSellerProductCall();
	private static Integer sellerId = Integer.valueOf(EnvSetup.getData("productsellerid"));
	private static String sellerName = EnvSetup.getData("productsellername");	
	private static YmtCatalogsIWapper ymtCatalogsIWapper = new YmtCatalogsIWapper();
	
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("商品改规格价格");
//		//SqlMapperFactory.getIntergratedProductMapper().updateProductoffSale(sellerId);
	}
	
	@Before
	public void caseUp() {
		
	}
	
	@AfterClass
	public static void tearDown() {
		Logger.generateResult(updatePriceBySkuCall.getOpurl());
	}
	
	@After
	public void caseDown() {
		Logger.end();
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_UpdatePriceBySku_001_001() {
		Logger.start(true,"修改多个价格，部分sku，部分catalogs，并多次修改");
		try{

			AddSellerProductRequest addProdReq = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			for(int i=0;i<6;i++){
				addProdReq.getProduct().getCatalogList().add(ProductManagerCallServiceV2.initCatalogSaveModel(10d,10,"颜色","颜色"+i));
			}
			List<String> skuList = generateSKUList(addProdReq.getProduct().getCatalogList().size());
			for (int i=0;i<addProdReq.getProduct().getCatalogList().size();i++){
				String sku=skuList.get(i);
				addProdReq.getProduct().getCatalogList().get(i).setSku(sku);
			}
			
			String productId = ProductManagerCallServiceV2.addNewProduct(addProdReq).get("Data").getAsJsonObject().get("ProductId").getAsString();
			Logger.comment("ProductId: " + productId);
			
			
			List<SKUPriceBean> skuPriceList = new ArrayList<>();
			for (int i=0;i<skuList.size();i++){
				SKUPriceBean skuPriceBean = new SKUPriceBean();
				if (i<(skuList.size()/2)){
					@SuppressWarnings("rawtypes")
					Map catalogInSql = ymtCatalogsIWapper.selectProductIdBySku(skuList.get(i)).get(0);
					skuPriceBean.setCatalogId(catalogInSql.get("sCatalogId").toString());
				}else{
					skuPriceBean.setSkuId(skuList.get(i));
				}
				
				skuPriceList.add(skuPriceBean);
			}
			
			
			
			
			//===============================================================================================================
			//只改原价
			generateBeanSKUStock(skuPriceList,true,false,false);
			//获取修改前价格
			List<SKUPriceBean> originalPriceList1 = getOriginalBeanSKUPriceList(skuPriceList);
			//修改价格
			JSONObject retBean1 = updatePriceBySkuCall.update(sellerId, skuPriceList);
			Logger.verifyEquals(200, retBean1.getInt("Code"), "返回code检查");
			//check
			checkPriceBySku(retBean1.getJSONObject("Data").getJSONArray("SkuResults"),skuPriceList,originalPriceList1);
			
			
			
			//===============================================================================================================
			//只改vip价格
			generateBeanSKUStock(skuPriceList,false,true,false);
			//获取修改前价格
			List<SKUPriceBean> originalPriceList2 = getOriginalBeanSKUPriceList(skuPriceList);
			//修改价格
			JSONObject retBean2 = updatePriceBySkuCall.update(sellerId, skuPriceList);
			Logger.verifyEquals(200, retBean2.getInt("Code"), "返回code检查");
			//check
			checkPriceBySku(retBean2.getJSONObject("Data").getJSONArray("SkuResults"),skuPriceList,originalPriceList2);
			
			
			
			//===============================================================================================================
			//只改新客价
			generateBeanSKUStock(skuPriceList,false,false,true);
			//获取修改前价格
			List<SKUPriceBean> originalPriceList3 = getOriginalBeanSKUPriceList(skuPriceList);
			//修改价格
			JSONObject retBean3 = updatePriceBySkuCall.update(sellerId, skuPriceList);
			Logger.verifyEquals(200, retBean3.getInt("Code"), "返回code检查");
			//check
			checkPriceBySku(retBean3.getJSONObject("Data").getJSONArray("SkuResults"),skuPriceList,originalPriceList3);
			
			
			
			//===============================================================================================================
			//全部修改
			generateBeanSKUStock(skuPriceList,true,true,true);
			//获取修改前价格
			List<SKUPriceBean> originalPriceList4 = getOriginalBeanSKUPriceList(skuPriceList);
			//修改价格
			JSONObject retBean4 = updatePriceBySkuCall.update(sellerId, skuPriceList);
			Logger.verifyEquals(200, retBean4.getInt("Code"), "返回code检查");
			//check
			checkPriceBySku(retBean4.getJSONObject("Data").getJSONArray("SkuResults"),skuPriceList,originalPriceList4);
			
			
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_UpdatePriceBySku_001() {
		Logger.start(true,"修改多个SKU的价格，并多次修改");
		try{
			AddSellerProductRequest addProdReq = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			
			for(int i=0;i<6;i++){
				addProdReq.getProduct().getCatalogList().add(ProductManagerCallServiceV2.initCatalogSaveModel(10d,10,"颜色","颜色"+i));
			}
			List<String> skuList = generateSKUList(addProdReq.getProduct().getCatalogList().size());
			for (int i=0;i<addProdReq.getProduct().getCatalogList().size();i++){
				String sku=skuList.get(i);
				addProdReq.getProduct().getCatalogList().get(i).setSku(sku);
			}
			
			String productId = ProductManagerCallServiceV2.addNewProduct(addProdReq).get("Data").getAsJsonObject().get("ProductId").getAsString();
			
			
			//===============================================================================================================
			//只改原价
			List<SKUPriceBean> skuPriceList1 = generateSKUStock(skuList,true,false,false);
			//获取修改前价格
			List<SKUPriceBean> originalPriceList1 = getOriginalSKUPriceList(skuList);
			//修改价格
			JSONObject retBean1 = updatePriceBySkuCall.update(sellerId, skuPriceList1);
			Logger.verifyEquals(200, retBean1.getInt("Code"), "返回code检查");
			//check
			checkPriceBySku(retBean1.getJSONObject("Data").getJSONArray("SkuResults"),skuPriceList1,originalPriceList1);
			
			
			
			//===============================================================================================================
			//只改vip价格
			List<SKUPriceBean> skuPriceList2 = generateSKUStock(skuList,false,true,false);
			//获取修改前价格
			List<SKUPriceBean> originalPriceList2 = getOriginalSKUPriceList(skuList);
			//修改价格
			JSONObject retBean2 = updatePriceBySkuCall.update(sellerId, skuPriceList2);
			Logger.verifyEquals(200, retBean2.getInt("Code"), "返回code检查");
			//check
			checkPriceBySku(retBean2.getJSONObject("Data").getJSONArray("SkuResults"),skuPriceList2,originalPriceList2);
			
			
			
			//===============================================================================================================
			//只改新客价
			List<SKUPriceBean> skuPriceList3 = generateSKUStock(skuList,false,false,true);
			//获取修改前价格
			List<SKUPriceBean> originalPriceList3 = getOriginalSKUPriceList(skuList);
			//修改价格
			JSONObject retBean3 = updatePriceBySkuCall.update(sellerId, skuPriceList3);
			Logger.verifyEquals(200, retBean3.getInt("Code"), "返回code检查");
			//check
			checkPriceBySku(retBean3.getJSONObject("Data").getJSONArray("SkuResults"),skuPriceList3,originalPriceList3);
			
			
			
			//===============================================================================================================
			//全部修改
			List<SKUPriceBean> skuPriceList4 = generateSKUStock(skuList,true,true,true);
			//获取修改前价格
			List<SKUPriceBean> originalPriceList4 = getOriginalSKUPriceList(skuList);
			//修改价格
			JSONObject retBean4 = updatePriceBySkuCall.update(sellerId, skuPriceList4);
			Logger.verifyEquals(200, retBean4.getInt("Code"), "返回code检查");
			//check
			checkPriceBySku(retBean4.getJSONObject("Data").getJSONArray("SkuResults"),skuPriceList4,originalPriceList4);
			
			
			
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	
	
	@SuppressWarnings({ "unchecked", "rawtypes" })
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_UpdatePriceBySku_002() {
		Logger.start(true,"修改相同SKU的库存");
		try{
			AddSellerProductRequest addProdReq = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			List<String> skuList = generateSKUList(addProdReq.getProduct().getCatalogList().size());
			for (int i=0;i<addProdReq.getProduct().getCatalogList().size();i++){
				String sku=skuList.get(i);
				addProdReq.getProduct().getCatalogList().get(i).setSku(sku);
			}
			
			String productId = ProductManagerCallServiceV2.addNewProduct(addProdReq).get("Data").getAsJsonObject().get("ProductId").getAsString();
			Logger.comment("ProductId: " + productId);
			
			
			String productId2 = ProductManagerCallServiceV2.addNewProduct(addProdReq).get("Data").getAsJsonObject().get("ProductId").getAsString();
			Logger.comment("ProductId: " + productId2);
			
			//===============================================================================================================
			//只改原价
			List<SKUPriceBean> skuPriceList1 = generateSKUStock(skuList,true,false,false);
			double price = skuPriceList1.get(0).getPrice();
			//修改价格
			JSONObject retBean1 = updatePriceBySkuCall.update(sellerId, skuPriceList1);
			Logger.verifyEquals(200, retBean1.getInt("Code"), "返回code检查");
		
			//check
			YmtCatalogsIWapper ymtCatalogsIWapper = new YmtCatalogsIWapper();
			List<Map> retList = ymtCatalogsIWapper.selectProductIdBySku(skuList.get(0));
			
			Map<String,Object> ret1 = retList.get(0);
			Map<String,Object> ret2 = retList.get(1);
			double actPriceInSql1 = Double.parseDouble(ret1.get("fQuotePrice").toString());
			double actPriceInSql2 = Double.parseDouble(ret2.get("fQuotePrice").toString());
			
			Logger.verifyEquals(true , ((actPriceInSql1==price)&&(actPriceInSql2!=price))||((actPriceInSql1!=price)&&(actPriceInSql2==price)), "SKU: " +skuList.get(0)+ ",只能修改一个对应的SKU" );

		}catch(Exception e){
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_UpdatePriceBySku_003() {
		Logger.start(true,"修改11个sku价格");
		try{
			AddSellerProductRequest addProdReq = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			
			for(int i=0;i<6;i++){
				addProdReq.getProduct().getCatalogList().add(ProductManagerCallServiceV2.initCatalogSaveModel(10d,10,"颜色","颜色"+i));
			}
			List<String> skuList = generateSKUList(addProdReq.getProduct().getCatalogList().size());
			for (int i=0;i<addProdReq.getProduct().getCatalogList().size();i++){
				String sku=skuList.get(i);
				addProdReq.getProduct().getCatalogList().get(i).setSku(sku);
			}
			
			String productId = ProductManagerCallServiceV2.addNewProduct(addProdReq).get("Data").getAsJsonObject().get("ProductId").getAsString();
			
			
			//发布商品 带SKU
			Logger.comment("ProductId: " + productId);
			
			//===============================================================================================================
			//全部修改
			List<SKUPriceBean> skuPriceList4 = generateSKUStock(skuList,true,true,true);
			//获取修改前价格
			List<SKUPriceBean> originalPriceList4 = getOriginalSKUPriceList(skuList);
			//修改价格
			JSONObject retBean4 = updatePriceBySkuCall.update(sellerId, skuPriceList4);
			Logger.verifyEquals(200, retBean4.getInt("Code"), "返回code检查");
			//check
			checkPriceBySku(retBean4.getJSONObject("Data").getJSONArray("SkuResults"),skuPriceList4,originalPriceList4);
			
			
			//设置11个skulist
			List<String> new_skuList = generateSKUList(3);
			new_skuList.addAll(skuList);
			List<SKUPriceBean> skuPriceList5 = generateSKUStock(new_skuList,true,true,true);
			JSONObject retBean1 = updatePriceBySkuCall.update(sellerId, skuPriceList5);
			Logger.verifyEquals(400, retBean1.getInt("Code"), "返回code检查");
			
			
			//超过11个，修改失败，所以第一次修改的价格没有变化
			checkPriceBySku(retBean4.getJSONObject("Data").getJSONArray("SkuResults"),skuPriceList4,originalPriceList4);
			
			
			
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_UpdatePriceBySku_004() {
		Logger.start(true,"修改非该买手SKU的价格");
		try{
			AddSellerProductRequest addProdReq = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			
			for(int i=0;i<6;i++){
				addProdReq.getProduct().getCatalogList().add(ProductManagerCallServiceV2.initCatalogSaveModel(10d,10,"颜色","颜色"+i));
			}
			List<String> skuList = generateSKUList(addProdReq.getProduct().getCatalogList().size());
			for (int i=0;i<addProdReq.getProduct().getCatalogList().size();i++){
				String sku=skuList.get(i);
				addProdReq.getProduct().getCatalogList().get(i).setSku(sku);
			}
			
			String productId = ProductManagerCallServiceV2.addNewProduct(addProdReq).get("Data").getAsJsonObject().get("ProductId").getAsString();
			
			
			//发布商品 带SKU
			Logger.comment("ProductId: " + productId);
			
			//===============================================================================================================
			//全部修改
			List<SKUPriceBean> skuPriceList4 = generateSKUStock(skuList,true,true,true);
			//获取修改前价格
			List<SKUPriceBean> originalPriceList4 = getOriginalSKUPriceList(skuList);
			//修改价格
			JSONObject retBean4 = updatePriceBySkuCall.update(sellerId, skuPriceList4);
			Logger.verifyEquals(200, retBean4.getInt("Code"), "返回code检查");
			//check
			checkPriceBySku(retBean4.getJSONObject("Data").getJSONArray("SkuResults"),skuPriceList4,originalPriceList4);
			
			
			List<SKUPriceBean> skuPriceList5 = generateSKUStock(skuList,true,true,true);
			JSONObject retBean1 = updatePriceBySkuCall.update(12312, skuPriceList5);
			Logger.verifyEquals(200, retBean1.getInt("Code"), "返回code检查");
			JSONArray SkuResults = retBean1.getJSONObject("Data").getJSONArray("SkuResults");
			for (int i=0;i<SkuResults.length();i++){
				Logger.verifyEquals(false,SkuResults.getJSONObject(i).getBoolean("ExecSuccess"),"SKU:"+SkuResults.getJSONObject(i).getString("SkuId")+" 应修改失败");
			}
			
			//非该买手修改失败，所以第一次修改的库存没有变化
			checkPriceBySku(retBean4.getJSONObject("Data").getJSONArray("SkuResults"),skuPriceList4,originalPriceList4);
			
			
			
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_UpdatePriceBySku_005() {
		Logger.start(true,"修改不存在的SKU");
		try{
			List<String> skuList = generateSKUList(8);
			List<SKUPriceBean> skuPriceList = generateSKUStock(skuList,true,true,true);
			//获取修改前价格

			JSONObject retBean = updatePriceBySkuCall.update(sellerId, skuPriceList);
			Logger.verifyEquals(200, retBean.getInt("Code"), "返回code检查");
			
			JSONArray SkuResults = retBean.getJSONObject("Data").getJSONArray("SkuResults");
			for (int i=0;i<SkuResults.length();i++){
				Logger.verifyEquals(false,SkuResults.getJSONObject(i).getBoolean("ExecSuccess"),"SKU:"+SkuResults.getJSONObject(i).getString("SkuId")+" 应修改失败");
			}
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_UpdatePriceBySku_006() {
		Logger.start(true,"修改部分存在，部分不存在的SKU");
		try{
			AddSellerProductRequest addProdReq = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			List<String> skuList = generateSKUList(addProdReq.getProduct().getCatalogList().size());
			for (int i=0;i<addProdReq.getProduct().getCatalogList().size();i++){
				String sku=skuList.get(i);
				addProdReq.getProduct().getCatalogList().get(i).setSku(sku);
			}
			
			String productId = ProductManagerCallServiceV2.addNewProduct(addProdReq).get("Data").getAsJsonObject().get("ProductId").getAsString();
			Logger.comment("ProductId: " + productId);
			
			List<String> skuList2 = generateSKUList(4);
			
			List<SKUPriceBean> originalPriceList1 = getOriginalSKUPriceList(skuList);
			//正常修改 部分存在，部分不存在SKU
			List<SKUPriceBean> skuPriceList = generateSKUStock(skuList,true,true,true);
			List<SKUPriceBean> skuPriceList2 = generateSKUStock(skuList2,true,true,true);
			skuPriceList2.addAll(skuPriceList);
			JSONObject retBean = updatePriceBySkuCall.update(sellerId, skuPriceList2);
			Logger.verifyEquals(200, retBean.getInt("Code"), "返回code检查");
			JSONArray SkuResults = retBean.getJSONObject("Data").getJSONArray("SkuResults");
			for(int i=0;i<SkuResults.length();i++){
				if (skuList2.contains(SkuResults.getJSONObject(i).getString("SkuId"))){
					Logger.verifyEquals(false,SkuResults.getJSONObject(i).getBoolean("ExecSuccess"),"SKU:"+SkuResults.getJSONObject(i).getString("SkuId")+" 应修改失败");
				}
			}
			checkPriceBySku(retBean.getJSONObject("Data").getJSONArray("SkuResults"),skuPriceList,originalPriceList1);
			
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	@SuppressWarnings({ "unchecked", "rawtypes" })
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_UpdatePriceBySku_007() {
		Logger.start(true,"修改已删除商品SKU的价格失败");
		try{
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			List<String> skuList = new ArrayList<>();
			List<CatalogSaveModel> clist = addpro.getProduct().getCatalogList();
			for (int i=0;i<clist.size();i++){
				String sku="SKU"+TestDataManager.getRandomIntNum(10);
				skuList.add(sku);
				clist.get(i).setSku(sku);
			}
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			ProductManagerCallServiceV2.updateProductAction( productId,-1);
			//===============================================================================================================
			//只改原价
			List<SKUPriceBean> skuPriceList1 = generateSKUStock(skuList,true,false,false);
			double price = skuPriceList1.get(0).getPrice();
			//修改价格
			JSONObject retBean1 = updatePriceBySkuCall.update(sellerId, skuPriceList1);
			Logger.verifyEquals(200, retBean1.getInt("Code"), "返回code检查");
			JSONArray SkuResults = retBean1.getJSONObject("Data").getJSONArray("SkuResults");
			for(int i=0;i<SkuResults.length();i++){
				if (skuList.contains(SkuResults.getJSONObject(i).getString("SkuId"))){
					Logger.verifyEquals(false,SkuResults.getJSONObject(i).getBoolean("ExecSuccess"),"SKU:"+SkuResults.getJSONObject(i).getString("SkuId")+" 验证ExecSuccess为false");
					Logger.verifyEquals("无效的SKUID或规格ID，或商品已被删除",SkuResults.getJSONObject(i).getString("Msg"),"SKU:"+SkuResults.getJSONObject(i).getString("Msg")+" 已删除的商品无法更新价格");
				}
			}

		}catch(Exception e){
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_UpdatePriceBySku_008() {
		Logger.start(true,"通过sku修改商品价格时，过滤被删除的商品");
		try{
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			List<String> skuList = new ArrayList<>();
			List<CatalogSaveModel> clist = addpro.getProduct().getCatalogList();
			for (int i=0;i<clist.size();i++){
				String sku="SKU"+TestDataManager.getRandomIntNum(10);
				skuList.add(sku);
				clist.get(i).setSku(sku);
			}
			String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			String productId1 = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();
			ProductManagerCallServiceV2.updateProductAction( productId,-1);
			//===============================================================================================================
			//只改原价
			List<SKUPriceBean> skuPriceList1 = generateSKUStock(skuList,true,false,false);
			double price = skuPriceList1.get(0).getPrice();
			//修改价格
			JSONObject retBean1 = updatePriceBySkuCall.update(sellerId, skuPriceList1);
			Logger.verifyEquals(200, retBean1.getInt("Code"), "返回code检查");
			JSONArray SkuResults = retBean1.getJSONObject("Data").getJSONArray("SkuResults");
			for(int i=0;i<SkuResults.length();i++){
				if (skuList.contains(SkuResults.getJSONObject(i).getString("SkuId"))){
					Logger.verifyEquals(true,SkuResults.getJSONObject(i).getBoolean("ExecSuccess"),"SKU:"+SkuResults.getJSONObject(i).getString("SkuId")+" 验证ExecSuccess为false");
					Logger.verifyEquals("成功",SkuResults.getJSONObject(i).getString("Msg"),"SKU:"+SkuResults.getJSONObject(i).getString("Msg")+" 已删除的商品无法更新价格");
				}
			}
			
			List<Map> retList = ymtCatalogsIWapper.selectProductIdBySku(skuList.get(0));
			Logger.verifyNotEquals(retList.get(0).get("fQuotePrice"), retList.get(1).get("iNum"), "已删除的商品和未删除的商品，库存不同");
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_UpdatePriceBySku_009() {
		Logger.start(true,"通过sku修改商品价格时，降低奢品价格会降为普通商品");
		try{
			int sellerId=3383;
			AddSellerProductRequest addpro = ProductManagerCallServiceV2.initAddSellerProductRequest(sellerId);
			addpro.getProduct().getCatalogList().get(0).setPrice(10000);
			addpro.getProduct().getCatalogList().get(0).setNewPrice(10000);
			addpro.getProduct().getCatalogList().get(0).setVipPrice(10000);
			addpro.getProduct().getCatalogList().get(0).setMarketPrice(18000);
			
			
			List<String> skuList = new ArrayList<>();
			List<CatalogSaveModel> clist = addpro.getProduct().getCatalogList();
			for (int i=0;i<clist.size();i++){
				String sku="SKU"+TestDataManager.getRandomIntNum(10);
				skuList.add(sku);
				clist.get(i).setSku(sku);
			}
			String productId = ProductManagerCallServiceV3.AddSellerProduct(addpro);
			
			Thread.sleep(5000);
			//ProductManagerCallServiceV2.EqualsIsLuxury(productId, true);
			//只改原价
			List<SKUPriceBean> skuPriceList1 = new ArrayList<>();
			skuList.forEach(b->{
				SKUPriceBean sKUPriceBean = new SKUPriceBean();
				sKUPriceBean.setSkuId(b);
				sKUPriceBean.setPrice(200);
				sKUPriceBean.setVipPrice(100);
				sKUPriceBean.setNewPrice(100);
				skuPriceList1.add(sKUPriceBean);
			});
			
			
			//修改价格
			JSONObject retBean1 = updatePriceBySkuCall.update(sellerId, skuPriceList1);
			Logger.verifyEquals(200, retBean1.getInt("Code"), "返回code检查");
			JSONArray SkuResults = retBean1.getJSONObject("Data").getJSONArray("SkuResults");

			Thread.sleep(5000);
			ProductManagerCallServiceV2.EqualsIsLuxury(productId, false);			
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	
	
	public static List<String> generateSKUList(int num){
		List<String> skuList = new ArrayList<>();
		for (int i=0;i<num;i++){
			skuList.add("SKU"+TestDataManager.getRandomIntNum(10));
		}
		return skuList;
	}

	public static List<SKUPriceBean> generateSKUStock(List<String> skuList,boolean isPriceUpdate,boolean isVipPriceUpdate,boolean isNewPriceUpdate){
		List<SKUPriceBean> retList= new ArrayList<>();
		
		skuList.forEach(ele->{
			SKUPriceBean sKUPriceBean = new SKUPriceBean();
			sKUPriceBean.setSkuId(ele);
			if (isPriceUpdate){sKUPriceBean.setPrice((double)TestDataManager.getRandomIntNum(6)/100);}
			if (isVipPriceUpdate){sKUPriceBean.setVipPrice((double)TestDataManager.getRandomIntNum(5)/100);}
			if (isNewPriceUpdate){sKUPriceBean.setNewPrice((double)TestDataManager.getRandomIntNum(4)/100);}
			retList.add(sKUPriceBean);
		});
		return retList;
	}	
	
	
	public static List<SKUPriceBean> generateBeanSKUStock(List<SKUPriceBean> skuPriceBeanList,boolean isPriceUpdate,boolean isVipPriceUpdate,boolean isNewPriceUpdate){
		List<SKUPriceBean> retList= new ArrayList<>();
		
		skuPriceBeanList.forEach(sKUPriceBean->{
			if (isPriceUpdate){sKUPriceBean.setPrice((double)TestDataManager.getRandomIntNum(6)/100);}
			if (isVipPriceUpdate){sKUPriceBean.setVipPrice((double)TestDataManager.getRandomIntNum(5)/100);}
			if (isNewPriceUpdate){sKUPriceBean.setNewPrice((double)TestDataManager.getRandomIntNum(4)/100);}
			retList.add(sKUPriceBean);
		});
		return retList;
	}	
	
	
	public static void setSkuForAddProduct(List<String> skuList,JSONObject addProdRequest) throws JSONException{
		JSONArray catalogAry = addProdRequest.getJSONObject("Product").getJSONArray("Catalogs");
		int minNum = Math.min(skuList.size(),catalogAry.length());
		for(int i=0;i<minNum;i++){
			catalogAry.getJSONObject(i).put("SKU", skuList.get(i));
		}
	}
	
	@SuppressWarnings({ "rawtypes", "unchecked" })
	public static List<SKUPriceBean> getOriginalSKUPriceList(List<String> skuList){
		List<SKUPriceBean> retSKUPriceBeanList = new ArrayList<>();
		YmtCatalogsIWapper ymtCatalogsIWapper = new YmtCatalogsIWapper();
		
		skuList.forEach(skuId->{
			
			try {
				List<Map> retList= ymtCatalogsIWapper.selectProductIdBySku(skuId);
				Logger.verifyEquals(1, retList.size(), "SKU:"+skuId+", 应该只有一个对应的catalog");
				Map<String,Object> ret = retList.get(0);
				
				double actPriceInSql = Double.parseDouble(ret.get("fQuotePrice").toString());
				double actVipPriceInSql = Double.parseDouble(ret.get("fVipPrice").toString());
				double actNewPriceInSql = Double.parseDouble(ret.get("fNewCustomerPrice").toString());
				
				SKUPriceBean sKUPriceBean = new SKUPriceBean();
				sKUPriceBean.setSkuId(skuId);
				sKUPriceBean.setPrice(actPriceInSql);
				sKUPriceBean.setVipPrice(actVipPriceInSql);
				sKUPriceBean.setNewPrice(actNewPriceInSql);
				retSKUPriceBeanList.add(sKUPriceBean);

			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		});
		return retSKUPriceBeanList;
	}
	
	
	@SuppressWarnings({ "rawtypes", "unchecked" })
	public static List<SKUPriceBean> getOriginalBeanSKUPriceList(List<SKUPriceBean> skuPriceList){
		List<SKUPriceBean> retSKUPriceBeanList = new ArrayList<>();
		YmtCatalogsIWapper ymtCatalogsIWapper = new YmtCatalogsIWapper();
		
		skuPriceList.forEach(sKUPriceBean->{
			
			try {
				
				double actPriceInSql ;
				double actVipPriceInSql ;
				double actNewPriceInSql;
				
				//sql
				if (sKUPriceBean.getCatalogId()!=null&&!sKUPriceBean.getCatalogId().equals("null")){
					YmtCatalogsI ele = ymtCatalogsIWapper.selectCatalogsByCatalogId(sKUPriceBean.getCatalogId());
					actPriceInSql = ele.getfQuotePrice().doubleValue();
					actVipPriceInSql = ele.getfVipPrice().doubleValue();
					actNewPriceInSql = ele.getfNewCustomerPrice().doubleValue();
				}else{
					List<Map> retList = ymtCatalogsIWapper.selectProductIdBySku(sKUPriceBean.getSkuId());
					Logger.verifyEquals(1, retList.size(), "SKU:"+sKUPriceBean.getSkuId()+", 应该只有一个对应的catalog");
					Map<String,Object> ret = retList.get(0);
					actPriceInSql = Double.parseDouble(ret.get("fQuotePrice").toString());
					actVipPriceInSql = Double.parseDouble(ret.get("fVipPrice").toString());
					actNewPriceInSql = Double.parseDouble(ret.get("fNewCustomerPrice").toString());
				}
				
				
				SKUPriceBean newSKUPriceBean = new SKUPriceBean();
				
				newSKUPriceBean.setCatalogId(sKUPriceBean.getCatalogId());
				newSKUPriceBean.setSkuId(sKUPriceBean.getSkuId());
				newSKUPriceBean.setPrice(actPriceInSql);
				newSKUPriceBean.setVipPrice(actVipPriceInSql);
				newSKUPriceBean.setNewPrice(actNewPriceInSql);
				retSKUPriceBeanList.add(newSKUPriceBean);

			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		});
		return retSKUPriceBeanList;
	}
	
	
	/***
	 * 
	 * @param skuResults 返回报文skuResults节点
	 * @param updateSKUPriceList 修改价格bean
	 * @param originalSKUPriceList 原来的价格bean
	 */
	@SuppressWarnings({ "unchecked", "rawtypes" })
	public static void checkPriceBySku(JSONArray skuResults,List<SKUPriceBean> updateSKUPriceList,List<SKUPriceBean> originalSKUPriceList){
		YmtCatalogsIWapper ymtCatalogsIWapper = new YmtCatalogsIWapper();
		
		
		for (SKUPriceBean updateSKUPrice:updateSKUPriceList){
			try{
				
				String reqSku = String.valueOf(updateSKUPrice.getSkuId());
				String reqCatalogId = String.valueOf(updateSKUPrice.getCatalogId());
				
				SKUPriceBean orginalSKUPrice;
				
				if (reqCatalogId!=null&&!reqCatalogId.equals("null")){
					orginalSKUPrice = originalSKUPriceList.stream().filter(ele->ele.getCatalogId()!=null&&ele.getCatalogId().equals(reqCatalogId)).findFirst().orElse(null);
				}else{
					orginalSKUPrice = originalSKUPriceList.stream().filter(ele->ele.getSkuId()!=null&&ele.getSkuId().equals(reqSku)).findFirst().orElse(null);
				}
				
				
				double tgtPrice = updateSKUPrice.getPrice()==-1?orginalSKUPrice.getPrice():updateSKUPrice.getPrice();
				double tgtVipPrice = updateSKUPrice.getVipPrice()==-1?orginalSKUPrice.getVipPrice():updateSKUPrice.getVipPrice();
				double tgtNewPrice = updateSKUPrice.getNewPrice()==-1?orginalSKUPrice.getNewPrice():updateSKUPrice.getNewPrice(); ;
				
			
				
				
				//返回报文检查
				
				///boolean isFoundInRet = false;
				for(int j=0;j<skuResults.length();j++){
					if ((reqSku!=null&&skuResults.getJSONObject(j).getString("SkuId").equals(reqSku))
							||(!reqCatalogId.equals("null")&&reqCatalogId!=null&&skuResults.getJSONObject(j).getString("CatalogId").equals(reqCatalogId))){
						Logger.verifyEquals(true, skuResults.getJSONObject(j).getBoolean("ExecSuccess"), "ExecSuccess 返回报文检查"+reqCatalogId+","+reqSku);
						//isFoundInRet = true;
						break;
					}
				}
				
				
				String catalogId ;
				double actPriceInSql ;
				double actVipPriceInSql ;
				double actNewPriceInSql;
				
				//sql
				if (reqCatalogId!=null&&!reqCatalogId.equals("null")){
					YmtCatalogsI ele = ymtCatalogsIWapper.selectCatalogsByCatalogId(reqCatalogId);
					catalogId = ele.getsCatalogId();
					actPriceInSql = ele.getfQuotePrice().doubleValue();
					actVipPriceInSql = ele.getfVipPrice().doubleValue();
					actNewPriceInSql = ele.getfNewCustomerPrice().doubleValue();
				}else{
					List<Map> retList = ymtCatalogsIWapper.selectProductIdBySku(reqSku);
					Logger.verifyEquals(1, retList.size(), "SKU:"+reqSku+", 应该只有一个对应的catalog");
					Map<String,Object> ret = retList.get(0);
					catalogId = ret.get("sCatalogId").toString();
					actPriceInSql = Double.parseDouble(ret.get("fQuotePrice").toString());
					actVipPriceInSql = Double.parseDouble(ret.get("fVipPrice").toString());
					actNewPriceInSql = Double.parseDouble(ret.get("fNewCustomerPrice").toString());
				}
				
				
				Logger.verifyEquals(tgtPrice, actPriceInSql, "Sql price检查 SKU:"+reqCatalogId+","+reqSku);
				Logger.verifyEquals(tgtVipPrice, actVipPriceInSql, "Sql vip price检查 SKU:"+reqCatalogId+","+reqSku);
				Logger.verifyEquals(tgtNewPrice, actNewPriceInSql, "Sql new price检查 SKU:"+reqCatalogId+","+reqSku);
				
				
				
				
				//java mongo
				/*if (YmtMongoDriverFactroy.isNewJavaMgoCheck()){
					CatalogsWapper catalogsWapper = new CatalogsWapper();
					Map<String,Object> dataInMgo = catalogsWapper.getByCatalogId(catalogId);
					double actPriceInMgo = Double.parseDouble(dataInMgo.get("price").toString());
					double actVipPriceInMgo = Double.parseDouble(dataInMgo.get("vip").toString());
					double actNewPriceInMgo = Double.parseDouble(dataInMgo.get("newp").toString());
					
					Logger.verifyEquals(tgtPrice, actPriceInMgo, "Java Mongo price检查 SKU:"+reqCatalogId+","+reqSku);
					Logger.verifyEquals(tgtVipPrice, actVipPriceInMgo, "Java Mongo vip price检查 SKU:"+reqCatalogId+","+reqSku);
					Logger.verifyEquals(tgtNewPrice, actNewPriceInMgo, "Java Mongo new price检查 SKU:"+reqCatalogId+","+reqSku);
					
				}*/
				
				
				
			}catch(Exception e){
				e.printStackTrace();
			}
		}
		
		
		
		
		
	}
	
	
}
